var t = require("../../../@babel/runtime/helpers/interopRequireDefault"), e = t(require("../../../dist/dialog/dialog")), a = t(require("../../../utils/util")), i = getApp();

Page({
    data: {
        verifierList: [],
        storeId: 0,
        isLoadMore: !0,
        page: 1,
        totalPage: 0,
        keyword: ""
    },
    onLoad: function(t) {
        var e;
        "" !== (null !== (e = t.storeId) && void 0 !== e ? e : "") && this.setData({
            storeId: t.storeId
        });
    },
    onChange: function(t) {
        var e = t.detail;
        this.setData({
            checked: e
        });
    },
    onSearchChange: function(t) {
        var e = this, i = t.detail;
        this.setData({
            keyword: i
        }), this.timer && clearTimeout(this.timer), this.timer = setTimeout(function() {
            a.default.debounce(e.verifierList());
        }, 500);
    },
    verifierList: function() {
        var t = this, e = i.getNetAddresss("plugin.coupon-store.frontend.clerk-manage.clerkList"), a = {
            cstore_id: this.data.storeId,
            page: this.data.page,
            kwd: this.data.keyword
        };
        console.log(a), i._postNetWork({
            url: e,
            data: a,
            success: function(e) {
                var a = e.data, i = a.data.data;
                i.forEach(function(t) {
                    t.status ? t.checked = !0 : t.checked = !1;
                }), console.log(i), wx.hideLoading(), wx.hideNavigationBarLoading(), wx.stopPullDownRefresh(), 
                1 == a.result ? (t.data.isLoadMore = !0, t.data.totalPage = a.data.last_page, t.data.totalPage || (t.data.totalPage = 0), 
                t.setData({
                    verifierList: i
                })) : (t.data.page = t.data.page - 1, t.isLoadMore = !1, wx.showToast({
                    icon: "none",
                    title: a.msg,
                    duration: 1500
                }));
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    getMoreData: function() {
        var t = this;
        if (this.data.isLoadMore = !1, !(this.data.page >= this.data.totalPage)) {
            this.data.page = this.data.page + 1;
            var e = i.getNetAddresss("plugin.coupon-store.frontend.clerk-manage.clerkList"), a = {
                cstore_id: this.data.storeId,
                page: this.data.page,
                kwd: this.data.keyword
            };
            i._getNetWork({
                url: e,
                data: a,
                success: function(e) {
                    var a = e.data, i = a.data.data;
                    i.forEach(function(t) {
                        t.checked = !0;
                    }), 1 == a.result ? (t.data.isLoadMore = !0, t.setData({
                        verifierList: t.data.verifierList.concat(i)
                    })) : (t.data.page = t.data.page - 1, t.isLoadMore = !1, wx.showToast({
                        icon: "none",
                        title: a.msg,
                        duration: 1500
                    }));
                },
                fail: function(t) {
                    console.log(t);
                }
            });
        }
    },
    verifierUpdate: function(t) {
        var e = JSON.stringify(t.currentTarget.dataset.id);
        wx.navigateTo({
            url: "/packageF/consumption/verifier/verifier?storeId=".concat(this.data.storeId, "&itemId=").concat(e)
        });
    },
    verifierDelete: function(t) {
        var a = t.currentTarget.dataset.id, o = this, s = i.getNetAddresss("plugin.coupon-store.frontend.clerk-manage.deleteClerk"), r = {
            cstore_id: this.data.storeId,
            id: a
        };
        e.default.confirm({
            title: "提示",
            message: "是否确认删除核销员"
        }).then(function() {
            i._postNetWork({
                url: s,
                data: r,
                success: function(t) {
                    var e = t.data;
                    1 == e.result ? (wx.showToast({
                        icon: "none",
                        title: e.msg,
                        duration: 1500
                    }), o.setData({
                        page: 1
                    }), o.verifierList()) : wx.showToast({
                        icon: "none",
                        title: e.msg,
                        duration: 1500
                    });
                },
                fail: function(t) {
                    console.log(t);
                }
            });
        }).catch(function() {});
    },
    onVerifierChange: function(t) {
        var e = t.currentTarget.dataset.index, a = t.currentTarget.dataset.item, o = this.data.verifierList;
        o[e].checked = t.detail;
        var s = this, r = i.getNetAddresss("plugin.coupon-store.frontend.clerk-manage.statusClerk"), n = {
            cstore_id: this.data.storeId,
            id: a.id,
            status: t.detail ? 1 : 0
        };
        console.log(this.data.storeId), i._postNetWork({
            url: r,
            data: n,
            success: function(t) {
                var e = t.data;
                1 == e.result ? (console.log(e), s.setData({
                    verifierList: o
                })) : wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    onReady: function() {},
    onShow: function() {
        this.verifierList();
    },
    onAddition: function() {
        wx.navigateTo({
            url: "/packageF/consumption/verifier/verifier?storeId=".concat(this.data.storeId)
        });
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {
        wx.showNavigationBarLoading(), wx.showLoading({
            title: "刷新中..."
        }), this.setData({
            page: 1
        }), this.verifierList();
    },
    onReachBottom: function() {
        this.data.isLoadMore ? this.getMoreData() : console.log("没有更多了");
    },
    onShareAppMessage: function() {}
});